package zju.ccnt.rest.domain;

import zju.ccnt.rest.api.ApiCreateBusinessResource;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by zha on 14/11/11.
 */
@Entity
public class BusinessResource extends BaseEntity{

    private String name;
    private String classId;
    private String description;
    private String hashValue;
    private String businessId;
    private boolean hasUploaded;

    //orm datas
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "hashValue", insertable = false, updatable = false)
    private Resource resource;

//    @ManyToOne(fetch = FetchType.EAGER)
//    @JoinColumn(name = "uploaderId", insertable = false, updatable = false)
    //todo 添加资源关联的上传者，表resurce_action
//    private EndUser endUser;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "businessId", insertable = false, updatable = false)
    private BusinessUser businessUser;

    public BusinessResource(ApiCreateBusinessResource apiResource){
        //TODO 好像不加super也会自动生成ID。。。
        super();
        this.name = apiResource.getName();
        this.classId = apiResource.getClassId();
        this.description = apiResource.getDescription();
        this.businessId = apiResource.getBusinessId();
        this.hashValue = apiResource.getHashValue();
    }

    public BusinessResource(){}

    public boolean getHasUploaded() {
        return hasUploaded;
    }

    public void setHasUploaded(boolean hasUploaded) {
        this.hasUploaded = hasUploaded;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getClassId() {
        return classId;
    }

    public void setClassId(String classId) {
        this.classId = classId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getBusinessId() {
        return businessId;
    }

    public void setBusinessId(String businessId) {
        this.businessId = businessId;
    }

    public Resource getResource() {
        return resource;
    }

    public void setResource(Resource resource) {
        this.resource = resource;
    }

    public BusinessUser getBusinessUser() {
        return businessUser;
    }

    public void setBusinessUser(BusinessUser businessUser) {
        this.businessUser = businessUser;
    }

    public String getHashValue() {
        return hashValue;
    }

    public void setHashValue(String hashValue) {
        this.hashValue = hashValue;
    }

    public boolean isHasUploaded() {
        return hasUploaded;
    }
}
